﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using DevExpress.Data.Linq;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using ECare.BUS;
using ECare.BUS.Data;
using ECare.Client.templates;

namespace ECare.Client.frms
{
    public partial class frmHome : frmNull
    {
        public frmHome()
        {
            InitializeComponent();
        }

        private void frmHome_Load(object sender, EventArgs e)
        {
            this.LoadItems();

            this.LoadData();
        }

        private void LoadItems()
        {
            this.tileControl1.Groups.Clear();

            var items = ModulesHelper.GetMenuItems();
            var topitems = items.Where(a => a.ModuleParentId == -1);
            foreach (var item in topitems)
            {
                //dont need to show the welcome page again
                if (item.ModuleId == 1)
                    continue;

                var newgroup = new TileGroup();
                this.tileControl1.Groups.Add(newgroup);

                foreach (var child in item.Children)
                {
                    var newitem = new TileItem();
                    newitem.ItemSize = child.Size == ItemSize.Large
                        ? TileItemSize.Large
                        : child.Size == ItemSize.Medinum
                            ? TileItemSize.Medium
                            : child.Size == ItemSize.Small ? TileItemSize.Small
                                : child.Size == ItemSize.Wide ? TileItemSize.Wide : TileItemSize.Default;

                    newitem.Text = child.ModuleName;
                    newitem.Tag = child.frmType;
                    newitem.AppearanceItem.Normal.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(114)))), ((int)(((byte)(198)))));

                    newgroup.Items.Add(newitem);

                }


            }

        }


        public void LoadData()
        {
            this.chartPlan.Series.Clear();



            var planworking = PlanHelper.GetPlans("1=1 ",true);

            var totalseris = new DevExpress.XtraCharts.Series();
            totalseris.Name = "计划数";

            var unfinishedseris = new DevExpress.XtraCharts.Series();
            unfinishedseris.Name = "未完成";

            foreach (var plan in planworking)
            {
                string plananme = plan.plan_id+"_"+plan.plan_date.ToShortDateString() + "_" + FormulaHelper.GetFormulaInfoById(plan.formula_id);
                totalseris.Points.Add(new SeriesPoint { Argument = plananme, Values = new double[] { plan.plan_times } });

                var pendingcount = PlanHelper.GetPlanDetails(plan).Count(a => a.plan_detail_status == PlanStatus.pending);


                unfinishedseris.Points.Add(new SeriesPoint { Argument = plananme, Values = new double[] { pendingcount } });
            }

     //       DevExpress.XtraCharts.FullStackedBarSeriesView fullStackedBarSeriesView1 = new DevExpress.XtraCharts.FullStackedBarSeriesView();
     //       totalseris.View = fullStackedBarSeriesView1;

      //      DevExpress.XtraCharts.FullStackedBarSeriesView fullStackedBarSeriesView2 = new DevExpress.XtraCharts.FullStackedBarSeriesView();
      //      unfinishedseris.View = fullStackedBarSeriesView2;

            this.chartPlan.Series.Add(totalseris);
            this.chartPlan.Series.Add(unfinishedseris);


        }


    }
}
